/*
	goods
*/
$(function(){
//debug
	if('{$debug}')
	{
		var desc_img = $(".desc_img1 img")	
		var gal_img  = $(".gallery img")
		var com = desc_img.add(gal_img)
		for(var i=0;i<com.length;i++)
		{
			var ele = com.eq(i)
			ele.parent("a").click(function(){ return false})
			var html = '<div><input type="button" name="'+ele.attr("src")+'" onclick="asOriginal(this.name)" value="作为封面图">'
			html += '<input type="button" name="'+ele.attr("src")+'" onclick="delImg(this.name)" value="删除图片"></div>'
			ele.after(html)
		}
	}	
})
function delImg(src)
{
	if(src)
	{
		var data = "act=del_img&src="+src
		Main.AJAX("debug.php",data,asOriginalRes)
	}
}
function asOriginal(src,goods_id){
	
	if(src)
	{
		var data = "act=change_ori&goods_id="+goods_id+"&src="+src
		Main.AJAX("ajax.php",data)
	}
}
function changeAttrs(){
	var attr = $(".cg_attrs").val()
	var a_id  = $(".a_id")
	var atr_id = 0
	for(var i=0;i<a_id.length;i++)
	{
		ele = a_id.eq(i)
		if(ele.attr("checked")=='checked')
		{
			atr_id = ele.val()	
		}	
	}
	atr_id = new Number(atr_id)
	if(atr_id==0)
	{
		alert("请选择属性类型")
		return false	
	}
	else
	{
		var data = "act=change_attrs&goods_id="+goods_id+"&attr="+attr+'&atr_id='+atr_id
		Main.AJAX("debug.php",data,asOriginalRes)
	}
	
}
function asOriginalRes(res){
	Main.locationHref()
}